<!--
 * @description: 生成记录
 * @fileName: GenerateHistory
 * @author: 17076
 * @date: 2025/3/13-上午9:47
 * @version: V1.0.0
-->

<template>
  <cs-dialog
    :dialog="dialogOption"
    @onSubmit="save"
  >
    <div slot="content">
      <el-row :gutter="20">
        <el-col :span="13">
          <div class="history-list" :style="{ height: $baseTableHeight(170) + 'px' }">
            <div v-for="item in historyList" :key="item.id">
              <p>{{ item['time'] }}</p>
              <el-image
                v-if="item.images.length === 1"
                :src="item.images[0].src"
                :class="['big-image', currentLensImage === item.images[0].src ? 'active' : '']"
                @click.native="() => { currentLensImage = item.images[0].src }"
              />
              <div v-else ref="swiper" class="swiper-container">
                <div class="swiper-wrapper">
                  <div
                    v-for="(subItem, subIndex) in item.images"
                    :key="subIndex"
                    class="swiper-slide"
                  >
                    <el-image
                      :src="subItem.src"
                      :class="['small-image', currentLensImage === subItem.src ? 'active' : '']"
                      @click.native="() => { currentLensImage = subItem.src }"
                    />
                    <div class="lens-tag">
                      <el-checkbox label="设为镜头" />
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </el-col>
        <el-col :span="11">
          <div class="image-info" :style="{ height: $baseTableHeight(170) + 'px' }">
            <el-descriptions :column="1">
              <el-descriptions-item label="模型">
                <span>{{ imageData['model'] }}</span>
              </el-descriptions-item>
              <el-descriptions-item label="提示词">
                <span>{{ imageData['prompt'] }}<svg-icon icon-class="copy" style="margin-left: 10px;cursor: pointer" @click="handleCopy(imageData['prompt'])" /></span>
              </el-descriptions-item>
              <el-descriptions-item label="时长">
                <span>{{ imageData['duration'] }}</span>
              </el-descriptions-item>
              <el-descriptions-item label="场景">
                <span>{{ imageData['scenery'] }}</span>
              </el-descriptions-item>
              <el-descriptions-item label="迭代步数">
                <span>{{ imageData['step'] }}</span>
              </el-descriptions-item>
              <el-descriptions-item label="生成张数">
                <span>{{ `${imageData['size']}张` }}</span>
              </el-descriptions-item>
              <el-descriptions-item label="质量等级">
                <span>{{ imageData['qualityName'] }}</span>
              </el-descriptions-item>
            </el-descriptions>
          </div>
        </el-col>
      </el-row>
    </div>
  </cs-dialog>
</template>

<script>
import Swiper from 'swiper'
import 'swiper/css/swiper.css'
export default {
  name: 'GenerateHistory',
  data() {
    return {
      dialogOption: {
        top: '5%',
        width: '55%',
        appendToBody: true,
        title: {
          title: '生成记录'
        },
        show: false
      },
      // 当前选中的镜头
      currentLensImage: '1',
      // 生成的镜头历史
      historyList: [
        { id: 0, name: '镜头1', time: '2025-03-12 11:11:11', images: [
          { src: '1' }
        ] },
        { id: 1, name: '镜头1', time: '2025-03-12 11:12:11', images: [
          { src: '2' }, { src: '3' }, { src: '4' }
        ] },
        { id: 2, name: '镜头1', time: '2025-03-12 11:12:11', images: [
          { src: '5' }, { src: '6' }, { src: '7' }
        ] }
      ],
      // 对应图片数据
      imageData: {
        model: '我是图片莫平行数据',
        prompt: '我是提示词数据我是提示词数据我是提示词数据我是提示词数据我是提示词数据我是提示词数据我是提示词数据我是提示词数据我是提示词数据我是提示词数据我是提示词数据我是提示词数据我是提示词数据',
        duration: '10',
        scenery: '我是场景',
        step: '1',
        size: '1',
        qualityName: '标准'
      }
    }
  },
  methods: {
    show() {
      this.dialogOption.show = true
      this.$nextTick(() => {
        this.$refs.swiper.forEach((item, index) => {
          new Swiper(item, {
            // 循环模式
            loop: false,
            slidesPerView: 3,
            spaceBetween: 20
          })
        })
      })
    },
    // 复制到剪切板
    async handleCopy(text) {
      if (navigator.clipboard && navigator.clipboard.writeText) {
        // 使用Clipboard API
        try {
          await navigator.clipboard.writeText(text)
          this.$baseMessage.success('文本已复制到剪切板')
        } catch (err) {
          // 回退到document.execCommand
          document.execCommand('copy', false, text)
          this.$baseMessage.success('文本已复制到剪切板')
        }
      } else {
        // 直接使用document.execCommand作为回退方案
        document.execCommand('copy', false, text)
        this.$baseMessage.success('文本已复制到剪切板')
      }
    },
    save(callback) {
      callback(true)
    }
  }
}
</script>

<style scoped lang="scss">
.history-list {
  color: #FFFFFF;
  overflow-y: auto;
  padding: 0 10px;
  .big-image {
    width: 100%;
    height: 300px;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
  }
  .swiper-slide {
    position: relative;
    &:hover {
      .lens-tag {
        display: block;
      }
    }
  }
  .small-image {
    width: 100%;
    height: 100px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
  }
  .active {
    border: 1px solid $base-color-default;
  }
  .lens-tag {
    position: absolute;
    right: -1px;
    top: 0;
    background: linear-gradient( 90deg, #3766FF 0%, #04FFE0 100%);
    padding: 5px 8px;
    border-radius: 0 8px 0 8px;
    display: none;
  }
}
.image-info {
  background: #272C36;
  border-radius: 8px;
  padding: 20px;
  box-sizing: border-box;
}
::v-deep {
  .dialog-content {
    overflow: hidden;
  }
  .el-descriptions-item__label {
    color: #B6C7D1;
  }
}
</style>
